﻿using BPMS.Business;
using BPMS.Entity;
using BPMS.IBusiness;
using DotNet.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace BPMS.MVC.Controllers
{
    public class IPManagerController : BaseController
    {
        BPMS_IPBlacklistIBLL bpms_ipblacklistibll = new BPMS_IPBlacklistBLL();
        BPMS_IPBlacklist bpms_ipblacklist = new BPMS_IPBlacklist();

        #region 系统访问控制列表
        /// <summary>
        /// 系统访问控制列表
        /// </summary>
        /// <returns></returns>
        public ActionResult IPManagerList()
        {
            return View();
        }
        /// <summary>
        /// 处理数据
        /// </summary>
        public void LoadAction()
        {
            string active = Request["action"];                                          //提交类型
            string orderField = Request["pqGrid_OrderField"];                           //排序字段  
            string orderType = Request["pqGrid_OrderType"];                             //排序类型
            string pqGrid_Sort = Request["pqGrid_Sort"];                                //要显示字段
            string key = Request["key"];                                                //主键
            switch (active)
            {
                case "GridBindList"://加载列表
                    Response.Write(JsonHelper.PqGridJson<BPMS_IPBlacklist>(bpms_ipblacklistibll.GetList(), pqGrid_Sort));
                    Response.End();
                    break;
                case "Delete":    //删除数据
                    Response.Write(bpms_ipblacklistibll.Delete(key));
                    Response.End();
                    break;
                default:
                    break;
            }
        }
        #endregion

        #region 系统访问控制表单
        /// <summary>
        /// 系统访问控制表单
        /// </summary>
        /// <returns></returns>
        public ActionResult IPManagerForm()
        {
            return View();
        }
        /// <summary>
        /// 确认事件
        /// </summary>
        /// <param name="bpms_ipblacklist">实体类</param>
        /// <returns></returns>
        public ActionResult AcceptClick(BPMS_IPBlacklist bpms_ipblacklist)
        {
            string key = Request["key"];                                                //主键
            bool IsOk = false;
            if (!string.IsNullOrEmpty(key))//判断是否编辑
            {
                bpms_ipblacklist.IPBlacklistId = key;
                bpms_ipblacklist.ModifyDate = DateTime.Now;
                bpms_ipblacklist.ModifyUserId = SessionHelper.GetSessionUser().UserId;
                bpms_ipblacklist.ModifyUserName = SessionHelper.GetSessionUser().UserName;
                IsOk = bpms_ipblacklistibll.Update(bpms_ipblacklist);
            }
            else
            {
                bpms_ipblacklist.IPBlacklistId = CommonHelper.GetGuid;
                bpms_ipblacklist.CreateUserId = SessionHelper.GetSessionUser().UserId;
                bpms_ipblacklist.CreateUserName = SessionHelper.GetSessionUser().UserName;
                IsOk = bpms_ipblacklistibll.Insert(bpms_ipblacklist);
            }
            return Content(IsOk.ToString().ToLower());
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        /// <param name="key">主键</param>
        /// <returns></returns>
        public ActionResult InitControl(string key)
        {
            if (!string.IsNullOrEmpty(key))
            {
                bpms_ipblacklist = bpms_ipblacklistibll.GetEntity(key);
                return Content(JsonHelper.ObjectToJson(bpms_ipblacklist));
            }
            return null;
        }
        #endregion
    }
}
